package com.bling.common.util;

import java.io.Serializable;
import java.util.Random;
/**
 * 生成随机验证码
 * @author BLingSoft
 *
 */
public class RandomCode implements Serializable{

	private static final long serialVersionUID = -9140344276835797935L;

	/**
	 * 产生随机验证码
	 * 数组第一个值是表达式，第二个值是结果
	 * @return
	 */
	public static String[] randomCode(){
		int num1 = 0;
		int num2 = 0;
		int sum = 0;
		int cal = 0;
		StringBuffer sb = new StringBuffer();
		Random random = new Random();
		num1 = random.nextInt(20);
		num2 = random.nextInt(20);
		cal = random.nextInt(2);
		if(num1<num2){
			int temp = num1;
			num1=num2;
			num2=temp;
		}
		switch(cal){
			case 0:
				sum=num1+num2;
				sb.append(num1).append("+").append(num2).append("=?");
				break;
			case 1:
				sum=num1-num2;
				sb.append(num1).append("-").append(num2).append("=?");	
				break;
		}
		return new String[]{sb.toString(),String.valueOf(sum)};
	}
	
}
